home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10491 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: erich.triumf.ca!bennett
  2. From: bennett@erich.triumf.ca (P.Bennett)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: HELP. How to convert '0x12' into FF char?
  5. Date: 17 Mar 1996 23:53 PST
  6. Organization: TRIUMF: Tri-University Meson Facility
  7. Distribution: world
  8. Message-ID: <17MAR199623533662@erich.triumf.ca>
  9. References: <4iissm$s76@nntp.ucs.ubc.ca>
  10. NNTP-Posting-Host: erich.triumf.ca
  11. News-Software: VAX/VMS VNEWS 1.50    
  12.  
  13. In article <4iissm$s76@nntp.ucs.ubc.ca>, gordonw@unixg.ubc.ca (Gordon Wong) writes...
  14. >Let's say we have d='1' and e='2' and the following code segment:
  15.  
  16. >f='0x';
  17. >strcpy(f,d);
  18. >strcpy(f,e);
  19. >f now contains the string '0x12' right?
  20.  
  21. No.
  22. but if you have:
  23.     char f[10] = "0x";
  24.     char d[2] = "1";
  25.     char e[2] = "2";
  26.     strcpy(f,d);
  27.     strcpy(f,e);
  28. f will then contain the string "0x12".
  29. Note that single quotes (') are used to delimit a single char.  double quotes
  30. (") are used to delimit a string (one or more chars terminated with a zero
  31. byte)
  32.     
  33.  
  34. >How would I write that out as a single ASCII FF character?
  35. >(d,e,f are char)
  36.  
  37. With my revision above...
  38.     int i;
  39.     sscanf(f, "%d", i);
  40.     putchar(i);   /* or printf("%c", i);
  41.  
  42.  
  43. Peter Bennett VE7CEI                | Vessels shall be deemed to be in sight
  44. Internet: bennett@triumf.ca         | of one another only when one can be
  45. Packet: ve7cei@ve7kit.#vanc.bc.ca   | observed visually from the other
  46. TRIUMF, Vancouver, B.C., Canada     |                          ColRegs 3(k)
  47. GPS and NMEA info and programs: ftp://sundae.triumf.ca/pub/peter/index.html
  48. or: ftp://ftp-i2.informatik.rwth-aachen.de/pub/arnd/GPS/peter/index.html
  49.  
  50.